<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>H+ 后台主题UI框架 - 空白页</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico"> <link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__STATIC__/layout/css/font-awesome.css?v=4.4.0" rel="stylesheet">
     <!-- jqgrid-->
    <link href="__STATIC__/layout/css/animate.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
    
     <link rel="stylesheet" href="__STATIC__/layout/css/channel.css" type="text/css">

    <link href="__STATIC__/layout/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
  
    <link rel="stylesheet" href="__STATIC__/layout/css/zTreeStyle.css" type="text/css">

    <style>
		   .radio-inline input[type=radio] {
            margin-top: 4px
        }
        .note-editable{height: 200px}
      
        #hesuan{
        	display: none;
        }
        .red{border-color:red;}
    </style>
</head>

<body style="color:#333;padding:3px; overflow-x: auto;">
    <!-- 标题 -->
    <div class="page-heade">
      <h1 class="title_color">添加常规促销申请明细</h1>
    </div>
    <!-- 标题 -->
    <div class="row-margin-top">
    <form id="f1"  method="post"  class="form-inline">
    <input type="hidden" name="tiapplyid" id="tiapplyid" {if condition="$aid neq 0"} value="{$aid}" {/if}/>
       <table class="table-bordered table t_table">
           <tr>
            <td style="min-width: 180px;width: 180px" class="text-right"><label for="" >网点<span class="colorRed">*</span>：</label></td>
            <td colspan="3">
                    <div class="col-xs-4">
                        <div class="input-group" id="" >
                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="net"  value="{:isset($supply)?$supply.jxs:''}">
                            <input type="hidden" name="nets" id="nets"/>
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-4">
                        <button class="btn btn-primary btn-sm" id="select_net">选择</button>
                        <input type="button" class="btn btn-primary btn-sm" id="clear_net" value="清空"/>
                        <a href="javascript:;" id="select_my_net">选择我的常用网点分组</a>
                    </div>
                </td>
           </tr>
           <tr>
             <td style="min-width: 180px;width: 180px" class="text-right"><label for="" >您选定的网点是：</label></td>
             <td class="text-left" colspan="3">
                    <div class="duoxuan" id="selected_net">
                        {if isset($list)}
                        {volist name="list.net" id="row"}
                        <span class="ren" data-id="{$row.id}">{$row.title}<span class="close">×</span></span>
                        {/volist}
                        {/if}
                    </div>
                </td>
           </tr>
          <tr>
                <td style="min-width: 180px;width: 180px" class="text-right">
                    <label for="">产品<span class="colorRed">*</span>：</label></td>
                <td colspan="3">
                    <div class="col-xs-4">
                        <div class="input-group" id="" >
                            <input type="text"   placeholder="请输入关键字或空格查询" class="form-control inputremindPeple" id="product"  value="{:isset($supply)?$supply.jxs:''}">
                            <input type="hidden" name="pros" id="pros"/>
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-2">
                        <button class="btn btn-primary btn-sm" id="select_product">选择</button>
                        <input type="button" class="btn btn-primary btn-sm" id="clear_product" value="清空"/>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 180px;width: 180px" class="text-right"><label for="">您选定的产品是：</label></td>
                <td class="text-left" colspan="3">
                    <div class="duoxuan" id="selected_product"></div>
                </td>
            </tr>
          
             <tr>
            <td style="min-width: 180px;width: 180px" class="text-right"><label for="" >促销执行时间<span class="colorRed">*</span>：</label></td>
            <td>
            <div class="form-group">
            <input type="text" id="start" class="form-control layer-date " style="min-width:100px;height: 26px;display: inline-block;" name="start">
           </div>
            <div class="form-group">
                至
            </div>
           <div class="form-group">
            <input type="text" class="form-control layer-date" style="min-width:100px;height: 26px;display: inline-block;" id="end" name="end">
           </div>
            </td>
            <td style="min-width: 180px;width: 180px" class="text-right"><label for="" >负责人<span class="colorRed">*</span>：</label></td>
            <td><input type="text" class="form-control" style="min-width: 220px;width: 220px" name="fuzeren" value="{$eu_name}"></td>
           </tr>
           <tr>
            <td style="min-width: 180px;width: 180px" class="text-right"><label for="" >预计核销时间<span class="colorRed">*</span>：</label></td>
            <td colspan="3">
                  <div class="form-group">
            <input type="text" id="yjverifyTime" class="form-control layer-date " style="min-width:100px;height: 26px;display: inline-block;" name="yjverifyTime">
           </div>
            </td>
           </tr>
        </table>
    <table class="table-bordered table t_table" >
    	<thead>
        <tr>
            <th colspan="7" class="text-center font-bold">三级费用科目</th>
        </tr>
        <tr class="info">
            <th class="text-center">费用名称</th>
            <th class="text-center">未税总额(元)<span class="colorRed">*</span><span class="helpText">帮</span></th>
            <th class="text-center">费用支付方式<span class="colorRed">*</span></th>
            <th class="text-center">费用计入部门<span class="colorRed">*</span></th>
            <th class="text-center">费用计入方案</th>
            <th class="text-center">费用描述</th>
            <th class="text-center"><button class="btn-success btn btn-sm" type="button"  id="add">添加</button></th>
        </tr>
        </thead>
        <tbody id="table1">
        <tr id="hesuan">
			<td>
            <input type="hidden" value="1" id="youhuiwho" name="youhuiwho"/>
				<select name="youtype" id="youtype" class="form-control select">
					<option value="0" tid="1" selected>请选择</option>
					{volist name="youhui" id="row"}
                        <option value="{$row.id}" {if $row.tejiabuchatype==11} tid='1' {else/} tid='2' {/if}>{$row.title}</option>
                        {/volist}
				</select>
			</td>
			<td><input type="text" name="sumjian" id="sumjian" value="0" readonly class="form-control"></td>
			 <td>
               <select name="jian_paymethod" id="jian_paymethod" class="form-control select">
                        <option value="0">请选择</option>
                        {volist name="fipay" id="row"}
                        <option value="{$row.id}">{$row.title}</option>
                        {/volist}
                    </select>  
            </td>
            <td>
				<div class="container-fluid">
                        <div class="row">
                            <div class="col-xs-8">
                                <div class="input-group" >
                                    <input type="text" placeholder="请输入关键字或空格查询" class="form-control jrbm" name="jian_jrbm" value="{:isset($supply)?$supply.jxs:''}">
                                    <div class="input-group-btn">
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                </div>
                                <div class="selectedOnlyOne " {if !isset($supply)}style="display:none;"{/if} >
                                    <span class="inin">{:isset($supply)?$supply.jxs_title:''}</span>
                                    <span class="close">×</span>
                                </div>
                            </div>
                            <div class="col-xs-4">
                                <button class="btn btn-primary btn-sm select_jrbm" type="button" >选择</button>
                            </div>
                        </div>
                    </div>
             </td>
             <td>
                <select name="jian_project" class="form-control select jian_project">
                        <option value="0">请选择</option>
                        {volist name="fijiru" id="row"}
                        <option value="{$row.id}">{$row.title}</option>
                        {/volist}
                    </select>   
            </td>
             <td><input type="text" name="jian_remark" class="form-control"></td> 
             <td></td>
        </tr>
        <tr class="feiyongxiang">
            <td> 
            	<div class="container-fluid">
                        <div class="row">
                            <div class="col-xs-8">
                                <div class="input-group" >
                                    <input type="text" placeholder="请输入关键字或空格查询" class="form-control feetype" name="feetype[]" value="{:isset($supply)?$supply.jxs:''}">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                </div>
                                <div class="selectedOnlyOne " {if !isset($supply)}style="display:none;"{/if} >
                                	
                                    <span class="inin">{:isset($supply)?$supply.jxs_title:''}</span>
                                    <span class="close">×</span>
                                </div>
                            </div>
                            <div class="col-xs-4">
                                <button class="btn btn-primary btn-sm feetree" type="button" >选择</button>
                            </div>
                        </div>
                    </div>
                </td>
            <td><input type="text num2" name="zonge[]" class="form-control zonge"></td>
            <td>
               <select name="paymethod[]"  class="form-control select paymethod">
                        <option value="0">请选择</option>
                        {volist name="fipay" id="row"}
                        <option value="{$row.id}">{$row.title}</option>
                        {/volist}
                    </select>  
            </td>
             <td>
				<div class="container-fluid">
                        <div class="row">
                            <div class="col-xs-8">
                                <div class="input-group" >
                                    <input type="text" placeholder="请输入关键字或空格查询" class="form-control jrbm"  name="jrbm[]" value="{:isset($supply)?$supply.jxs:''}">
                                    <div class="input-group-btn">
                                        <button  class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                </div>
                                <div class="selectedOnlyOne " {if !isset($supply)}style="display:none;"{/if} >
                                    <span class="inin">{:isset($supply)?$supply.jxs_title:''}</span>
                                    <span class="close">×</span>
                                </div>
                            </div>
                            <div class="col-xs-4">
                                <button class="btn btn-primary btn-sm select_jrbm" type="button">选择</button>
                            </div>
                        </div>
                    </div>
             </td>
             <td>
                <select name="project[]" class="form-control select project">
                        <option value="0">请选择</option>
                        {volist name="fijiru" id="row"}
                        <option value="{$row.id}">{$row.title}</option>
                        {/volist}
                    </select>   
            </td>
             <td><input type="text" name="remark[]" class="form-control"></td> 
             <td class="text-center"><button class="btn btn-danger btn-sm del_fi_item" type="button">删除</button> </td>
        </tr>
        </tbody>
    </table>
      <table class="table-bordered table t_table">
      	<thead>
        <tr>
            <th colspan="11" class="text-center font-bold">活动产品</th>
        </tr>
        <tr class="info">
            <th class="text-center">产品名称</th>
            <th class="text-center">规格</th>
            <th class="text-center">总预计销量<span class="colorRed">*</span><span class="helpText">帮</span></th>
            <th class="text-center">标准出厂价</th>
             <th class="text-center">经销商原供价<span class="colorRed">*</span><span class="helpText">帮</span></th>
            <th class="text-center">经销商特价<span class="colorRed">*</span></th>
            <th class="text-center">网点原供价<span class="colorRed">*</span></th>
            <th class="text-center">网点特价<span class="colorRed">*</span></th>
            <th class="text-center">需补差的销量</th>
            <th class="text-center">原零售价<span class="colorRed">*</span></th>
            <th class="text-center">活动期零售价<span class="colorRed">*</span></th>
        </tr>
        </thead>
        <tbody id="protr">
       
        </tbody>
        <tfoot>
			<tr>
            <td class="text-right" row="2">备注</td>
            <td colspan="10">
                <textarea name="beizhu" id="" rows="2" class="form-control" style="width: 50%"></textarea><span style="vertical-align: bottom;">(200)</span>
            </td>
        	</tr>
        </tfoot>
        
    </table>
       <div class="row sub_btn white-bg" style="width:100%;text-align:center;padding: 20px 0">
        <input type="button" id="baocunadd" class="btn btn-success" value="保存并再添加一条">
        <input type="button" id="baocunret" class="btn btn-success" value="保存并并返回">
       
        <input type="button" class="btn btn-warning" value="返回" id="fanhui">
    </div>
</form>
    </div>
    <!-- 全局js -->
   <!-- 全局js -->
    <script src="__STATIC__/layout/js/jquery.min.js?v=2.1.4"></script>
    <script src="__STATIC__/layout/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
    <script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
    <!-- <script src="js/plugins/layer/layer.min.js"></script> -->

    <!-- 自定义js -->
    <!-- <script src="js/hplus.js?v=4.1.0"></script> -->
    <!-- <script type="text/javascript" src="js/contabs.js"></script> -->
     <!-- Peity -->
    <script src="__STATIC__/layout/js/plugins/peity/jquery.peity.min.js"></script>

    <!-- jqGrid -->
    <script src="__STATIC__/layout/js/plugins/jqgrid/i18n/grid.locale-cn.js?0820"></script>
    <script src="__STATIC__/layout/js/plugins/jqgrid/jquery.jqGrid.min.js?0820"></script>

    <!-- 自定义js -->
    <script src="__STATIC__/layout/js/content.js?v=1.0.0"></script>
     <script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
    
    <!-- ztree -->
    <script type="text/javascript" src="__STATIC__/layout/js/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="__STATIC__/layout/js/jquery.ztree.excheck.js"></script>
    <!-- <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script> -->
    <!--统计代码，可删除-->
    <script src="__STATIC__/layout/js/plugins/layer/laydate/laydate.js"></script>
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>
    <!--统计代码，可删除-->
    <script>
    //验证网点供货价范围
    function netfanwei(){
        var flag=0; $(".xiannet").removeClass("red");
        $(".xiannet").each(function(){
            var high=$(this).next().next().next().val();
            var low=$(this).next().next().next().next().val();

            var own=parseFloat($(this).val());
            //alert(low);alert(high);alert(own)
            if(low!=""&&parseFloat(low)!=0){
                if(parseFloat(low)>own){
                    flag=1;
                    $(this).addClass("red")
                }
            }
            if(high!=""&&parseFloat(high)!=0){
                //alert(high)
                if(parseFloat(high)<own){
                    flag=1;
                    $(this).addClass("red")
                }
            }
        })
        $(".xianp").removeClass("red");
        $(".xianp").each(function(){
            var high=$(this).next().val();
            var low=$(this).next().next().val();
            var own=parseFloat($(this).val());
            if(low!=""&&parseFloat(low)!=0){
                if(parseFloat(low)>own){
                    flag=1;
                    $(this).addClass("red")
                }
            }
            if(high!=""&&parseFloat(high)!=0){
                //alert(high)
                if(parseFloat(high)<own){
                    flag=1;
                    $(this).addClass("red")
                }
            }
        })
        return flag;
    }
    var jxscha=0;var netcha=0;var type=1;
    $("#youtype").change(function(){
        type=parseInt($("#youtype>option:selected").attr("tid"));
        $("#youhuiwho").val(type);
       // alert(type);
         if(type==1){
                $("#sumjian").val(jxscha.toFixed(2));
            }else{
                $("#sumjian").val(netcha.toFixed(2));
            }
    })
    //计算补差金额
    function jisuanchae(){
        jxscha=0;netcha=0;
        $(".protrs").each(function(){
            //获取规格数
            var guige=parseInt($(this).children().eq(2).children().eq(0).html());
            //原经销
            var jxsyuan=parseFloat($(this).children().eq(5).children().eq(0).val());
            //现经销
            var jxsxian=parseFloat($(this).children().eq(6).children().eq(2).val());
            //网点原
            var netyuan=$(this).children().eq(7).children().eq(0).val();
           // alert(netyuan);
            //网点现
            var netxian=parseFloat($(this).children().eq(8).children().eq(2).val());
             //alert(netxian);
            //补差
            var bucha=$(this).children().eq(9).children().eq(0).val();
            if(bucha!=""){
                jxscha+=((jxsyuan-jxsxian)*guige*parseFloat(bucha));
                if(netyuan!=""){
                    netcha+=((parseFloat(netyuan)-netxian)*guige*parseFloat(bucha));
                }
            }
           
        })
        if(netcha==0&&jxscha==0){
            $("#sumjian").val(0);
            $("#hesuan").hide();
        }else{
            //$("#sumjian").val(netcha+jxscha);
            if(type==1){
                $("#sumjian").val(jxscha.toFixed(2));
            }else{
                $("#sumjian").val(netcha.toFixed(2));
            }
            $("#hesuan").show();
        }
      
    }
    //补差箱数变动
    $("body").on("blur",".chabox",function(){
          var $_cb=$(this);
             if(isNaN(parseFloat($_cb.val()))){
                $_cb.val(0);
            }else{
                 $_cb.val(parseFloat($_cb.val()).toFixed(2));
            }
        var cbox=parseFloat($_cb.val());
          //预计箱数
         var $_b=$(this).parent().prev().prev().prev().prev().prev().prev().children().eq(0);
             if(isNaN(parseFloat($_b.val()))){
                $_b.val(0);
            }else{
                 $_b.val(parseFloat($_b.val()).toFixed(2));
            }
            var box=parseFloat($_b.val());
           // alert(box);
            if(cbox>box){
                swal({
                                        title: "错误",
                                        text:  "需补差销量不能大于总预计销量",
                                        type: "warning"
                                        },function(){
                                            $_cb.val(box.toFixed(2));
                                        });
            }
            jisuanchae();
    })
    //原零售价变动
    $("body").on("blur",".yuanp",function(){
           var $_b=$(this);
             if(isNaN(parseFloat($_b.val()))){
                $_b.val(0);
            }else{
                 $_b.val(parseFloat($_b.val()).toFixed(2));
            }
             jisuanchae();
    })
    //预计箱数变动
    $("body").on("blur",".boxs",function(){
        //预计箱数
         var $_b=$(this);
             if(isNaN(parseFloat($_b.val()))){
                $_b.val(0);
            }else{
                 $_b.val(parseFloat($_b.val()).toFixed(2));
            }
            var box=parseFloat($_b.val());
        $(this).parent().nextAll().eq(5).children().eq(0).val(box);
         jisuanchae();
    })
    //活动期零售价变动
    $("body").on("blur",".xianp",function(){
          //促销价
            var $_c=$(this);
             if(isNaN(parseFloat($_c.val()))){
                $_c.val(0);
            }else{
                 $_c.val(parseFloat($_c.val()).toFixed(2));
            }
            var cuxiao=parseFloat($_c.val());
          //  alert(cuxiao);
            if(cuxiao==0){
                //alert( $(this).parent().prev().prev().prev().children().eq(4).val());
                $(this).parent().prev().prev().prev().children().eq(4).val("-100.00");
            }else{
                //网点现
                 var $_netx= $(this).parent().prev().prev().prev().children().eq(2);
                if(isNaN(parseFloat($_netx.val()))){
                    $_netx.val(0);
                }else{
                     $_netx.val(parseFloat($_netx.val()).toFixed(2));
                }
                var netxian=parseFloat($_netx.val());
                if(netxian==0){
                    $(this).parent().prev().prev().prev().children().eq(4).val("0.00");
                }else{
                    var netmao=(cuxiao-netxian)/netxian*100;
                    $(this).parent().prev().prev().prev().children().eq(4).val(netmao.toFixed(2));
                }
            }
             jisuanchae();
    })
    //网点现毛利变动
    $("body").on("blur",".netmao",function(){
             //网点原
        var $_nety=$(this).parent().prev().children().eq(0);
        if($_nety.val()!=""){
            if(isNaN(parseFloat($_nety.val()))){
                $_nety.val(0);
            }else{
                 $_nety.val(parseFloat($_nety.val()).toFixed(2));
            }
            
        }   
       var netyuan=parseFloat($_nety.val());
       //网点毛
         var $_netm=$(this);
             if(isNaN(parseFloat($_netm.val()))){
                $_netm.val(0);
            }else{
                 $_netm.val(parseFloat($_netm.val()).toFixed(2));
            }
            var netmao=parseFloat($_netm.val());
       if($_nety.val()==""||parseFloat($_nety.val())==0){
        $(this).val("0.00").prev().prev().val("0.00").prev().prev().val("0.00");
       }else{
              //促销价
            var $_c=$(this).parent().next().next().next().children().eq(0);
             if(isNaN(parseFloat($_c.val()))){
                $_c.val(0);
            }else{
                 $_c.val(parseFloat($_c.val()).toFixed(2));
            }
            var cuxiao=parseFloat($_c.val());

            if(cuxiao==0)
                 $(this).val("-100.00");
             else{
                //网点现价
                var netxian=cuxiao/(1+netmao/100);
                $(this).prev().prev().val(netxian.toFixed(2));
                netxian=parseFloat($(this).prev().prev().val());
                //网点折价
                  var netzhe=(netyuan-netxian)/netyuan*100;
                $(this).prev().prev().prev().prev().val(netzhe.toFixed(2));
                netzhe=parseFloat( $(this).prev().prev().prev().prev().val());
                 //经销商现
                var $_jxsx=$(this).parent().prev().prev().children().eq(2);
                if(isNaN(parseFloat($_jxsx.val()))){
                    $_jxsx.val(0);
                }else{
                     $_jxsx.val(parseFloat($_jxsx.val()).toFixed(2));
                }
                var jxsxian=parseFloat($_jxsx.val());
                     //经销商毛利率
                if(jxsxian==0)
                    var jxsmao=0;
                else
                    var jxsmao=(netxian-jxsxian)/jxsxian*100;
                $(this).parent().prev().prev().children().eq(4).val(jxsmao.toFixed(2));
             }
       }
        jisuanchae();
    })
    //网点现价变动
    $("body").on("blur",".xiannet",function(){
           //网点原
        var $_nety=$(this).parent().prev().children().eq(0);
        if($_nety.val()!=""){
            if(isNaN(parseFloat($_nety.val()))){
                $_nety.val(0);
            }else{
                 $_nety.val(parseFloat($_nety.val()).toFixed(2));
            }
            
        }   
       var netyuan=parseFloat($_nety.val());
         if($_nety.val()==""||parseFloat($_nety.val())==0){
             $(this).val("0.00").next().next().val("0.00");
             $(this).prev().prev().val("0.00");
        }else{
            //网点现
             var $_netx=$(this);
            if(isNaN(parseFloat($_netx.val()))){
                $_netx.val(0);
            }else{
                 $_netx.val(parseFloat($_netx.val()).toFixed(2));
            }
            var netxian=parseFloat($_netx.val());
            //网点折
            var netzhe=(netyuan-netxian)/netyuan*100;
            $(this).prev().prev().val(netzhe.toFixed(2));
            netzhe=parseFloat( $(this).prev().prev().val());
            //经销商现
            var $_jxsx=$(this).parent().prev().prev().children().eq(2);
            if(isNaN(parseFloat($_jxsx.val()))){
                $_jxsx.val(0);
            }else{
                 $_jxsx.val(parseFloat($_jxsx.val()).toFixed(2));
            }
            var jxsxian=parseFloat($_jxsx.val());
            //经销商毛利率
            if(jxsxian==0)
                var jxsmao=0;
            else
                var jxsmao=(netxian-jxsxian)/jxsxian*100;
           // alert(jxsmao);
            $(this).parent().prev().prev().children().eq(4).val(jxsmao.toFixed(2));
               //促销价
            var $_c=$(this).parent().next().next().next().children().eq(0);
             if(isNaN(parseFloat($_c.val()))){
                $_c.val(0);
            }else{
                 $_c.val(parseFloat($_c.val()).toFixed(2));
            }
            var cuxiao=parseFloat($_c.val());
              if(cuxiao==0)
                var netmao=-100;
            else
                var netmao=(cuxiao-netxian)/netxian*100;
            $(this).parent().children().eq(4).val(netmao.toFixed(2));
        }
         jisuanchae();
    })
    //网点折价变动
    $("body").on("blur",".netzhejia",function(){
         //网点原
        var $_nety=$(this).parent().prev().children().eq(0);
         if($_nety.val()==""||parseFloat($_nety.val())==0){
            if(isNaN(parseFloat($_nety.val()))){
                $_nety.val(0);
            }else{
                 $_nety.val(parseFloat($_nety.val()).toFixed(2));
            }
            
        }   
       var netyuan=parseFloat($_nety.val());
         if($_nety.val()==""||parseFloat($_nety.val())==0){
            $(this).val("0.00").next().next().val("0.00").next().next().val("0.00");
        }else{
            var $_netz=$(this);
            if(isNaN(parseFloat($_netz.val()))){
                $_netz.val(0);
            }else{
                 $_netz.val(parseFloat($_netz.val()).toFixed(2));
            }
            var netzhe=parseFloat($_netz.val());
            var netxian=netyuan-netyuan/100*netzhe;
            $(this).next().next().val(netxian.toFixed(2));
            netxian=parseFloat($(this).next().next().val());
            //经销商现
            var $_jxsx=$(this).parent().prev().prev().children().eq(2);
            if(isNaN(parseFloat($_jxsx.val()))){
                $_jxsx.val(0);
            }else{
                 $_jxsx.val(parseFloat($_jxsx.val()).toFixed(2));
            }
            var jxsxian=parseFloat($_jxsx.val());
                 //经销商毛利率
            if(jxsxian==0)
                var jxsmao=0;
            else
                var jxsmao=(netxian-jxsxian)/jxsxian*100;
            $(this).parent().prev().prev().children().eq(4).val(jxsmao.toFixed(2));
                 //促销价
            var $_c=$(this).parent().next().next().next().children().eq(0);
             if(isNaN(parseFloat($_c.val()))){
                $_c.val(0);
            }else{
                 $_c.val(parseFloat($_c.val()).toFixed(2));
            }
            var cuxiao=parseFloat($_c.val());
              if(cuxiao==0)
                var netmao=-100;
            else
                var netmao=(cuxiao-netxian)/netxian*100;
            $(this).parent().children().eq(4).val(netmao.toFixed(2));
            }
             jisuanchae();
    })
    //网点原变动
    $("body").on("blur",".netyuan",function(){
          //网点原
        var $_nety=$(this);
        if($_nety.val()!=""){
            if(isNaN(parseFloat($_nety.val()))){
                $_nety.val(0);
            }else{
                 $_nety.val(parseFloat($_nety.val()).toFixed(2));
            }
            
        }else{
            $_nety.val(0);
        }  
       var netyuan=parseFloat($_nety.val());
      
       //网点折价
        var $_netz=$(this).parent().next().children().eq(0);
          if(isNaN(parseFloat($_netz.val()))){
            $_netz.val(0);
        }else{
             $_netz.val(parseFloat($_netz.val()).toFixed(2));
        }
        var netzhe=parseFloat($_netz.val());
        //网点现
        var netxian=netyuan-netyuan*netzhe/100;
        $_netx=$(this).parent().next().children().eq(2);
        $_netx.val(netxian.toFixed(2));
        netxian=parseFloat($_netx.val());
        //经销商现
        var $_jxsx=$(this).parent().prev().children().eq(2);
        if(isNaN(parseFloat($_jxsx.val()))){
            $_jxsx.val(0);
        }else{
             $_jxsx.val(parseFloat($_jxsx.val()).toFixed(2));
        }
        var jxsxian=parseFloat($_jxsx.val());
        //经销商毛利率
        if(jxsxian==0)
            var jxsmao=0;
        else
            var jxsmao=(netxian-jxsxian)/jxsxian*100;
        $(this).parent().prev().children().eq(4).val(jxsmao.toFixed(2));
        //促销价
        var $_c=$(this).parent().next().next().next().next().children().eq(0);
         if(isNaN(parseFloat($_c.val()))){
            $_c.val(0);
        }else{
             $_c.val(parseFloat($_c.val()).toFixed(2));
        }
        var cuxiao=parseFloat($_c.val());
        if(netxian!=0)
            if(cuxiao==0)
                var netmao=-100;
            else
             var netmao=(cuxiao-netxian)/netxian*100;
        else
            var netmao=0;
       
        $(this).parent().next().children().eq(4).val(netmao.toFixed(2));
         jisuanchae();
    })
    //经销商毛利率变动
    $("body").on('blur',".jxsmao",function(){
          //原jxs供货价
        var $_y=$(this).parent().prev().children().eq(0);
        if(isNaN(parseFloat($_y.val()))){
            $_y.val(0);
        }else{
             $_y.val(parseFloat($_y.val()));
        }
        var jxsyuan=parseFloat($_y.val());
           //网点现
        var $_netx=$(this).parent().next().next().children().eq(2);
          if(isNaN(parseFloat($_netx.val()))){
            $_netx.val(0);
        }else{
             $_netx.val(parseFloat($_netx.val()).toFixed(2));
        }
        var netxian=parseFloat($_netx.val());
        //网点原
           var $_nety=$(this).parent().next().children().eq(0);
        if($_nety.val()!=""){
            if(isNaN(parseFloat($_nety.val()))){
                $_nety.val(0);
            }else{
                 $_nety.val(parseFloat($_nety.val()).toFixed(2));
            }
            
        }   
       var netyuan=parseFloat($_nety.val());
       //jxs毛利
        var $_jxsm=$(this);
         if(isNaN(parseFloat($_jxsm.val()))){
            $_jxsm.val(0);
        }else{
             $_jxsm.val(parseFloat($_jxsm.val()).toFixed(2));
        }
        var jxsmao=parseFloat($_jxsm.val());
        if(netyuan!=""){

           //求经销商现价
           if(jxsmao!=-100)
           {
            var jxsxian=netxian/(1+jxsmao/100);
            $(this).prev().prev().val(jxsxian.toFixed(2));
            jxsxian=parseFloat($(this).prev().prev().val());
            //求经销商折价
            //(jy-jx)/jy
            var jxszhe=(jxsyuan-jxsxian)/jxsyuan*100;
            $(this).prev().prev().prev().prev().val(jxszhe.toFixed(2));
            }
       }else{
        $(this).val("-100.00");
       }
        jisuanchae();
    })
    //折价变动
    $("body").on('blur',".jxszhejia",function(){
        //jxs税率
        var $_zhe=$(this);
         if(isNaN(parseFloat($_zhe.val()))){
            $_zhe.val(0);
        }else{
             $_zhe.val(parseFloat($_zhe.val()).toFixed(2));
        }
        var jxszhe=parseFloat($_zhe.val());
         //原jxs供货价
        var $_y=$(this).parent().prev().children().eq(0);
        if(isNaN(parseFloat($_y.val()))){
            $_y.val(0);
        }else{
             $_y.val(parseFloat($_y.val()));
        }
        var jxsyuan=parseFloat($_y.val());
        //现供货价
        var jxsxian=jxsyuan-jxsyuan*jxszhe/100;
        $(this).next().next().val(jxsxian.toFixed(2));
        jxsxian=parseFloat($(this).next().next().val());
           //网点现
        var $_netx=$(this).parent().next().next().children().eq(2);
          if(isNaN(parseFloat($_netx.val()))){
            $_netx.val(0);
        }else{
             $_netx.val(parseFloat($_netx.val()).toFixed(2));
        }
        var netxian=parseFloat($_netx.val());
        //网点原
           var $_nety=$(this).parent().next().children().eq(0);
        if($_nety.val()!=""){
            if(isNaN(parseFloat($_nety.val()))){
                $_nety.val(0);
            }else{
                 $_nety.val(parseFloat($_nety.val()).toFixed(2));
            }
            
        }   
       var netyuan=parseFloat($_nety.val());
       if(netyuan!=""){
            if(jxsxian==0)
            var maoli=0;
            else
             var maoli=(netxian-jxsxian)/jxsxian*100;
            
            $(this).next().next().next().next().val(maoli.toFixed(2));
       }
        jisuanchae();
    })
    //现供货价离开后自动调整为正确值
    $("body").on('blur',".xianjsx",function(){
        //jxs现供货价
        if(isNaN(parseFloat($(this).val()))){
            $(this).val(0);
        }else{
            $(this).val(parseFloat($(this).val()).toFixed(2));
        }
        var jxsxian=parseFloat($(this).val());
        //jxs税率
        var $_zhe=$(this).prev().prev();
         if(isNaN(parseFloat($_zhe.val()))){
            $_zhe.val(0);
        }else{
             $_zhe.val(parseFloat($_zhe.val()).toFixed(2));
        }
        var jxszhe=parseFloat($_zhe.val());
        //原jxs供货价
        var $_y=$(this).parent().prev().children().eq(0);
        if(isNaN(parseFloat($_y.val()))){
            $_y.val(0);
        }else{
             $_y.val(parseFloat($_y.val()));
        }
        var jxsyuan=parseFloat($_y.val());
        //网点现
        var $_netx=$(this).parent().next().next().children().eq(2);
          if(isNaN(parseFloat($_netx.val()))){
            $_netx.val(0);
        }else{
             $_netx.val(parseFloat($_netx.val()).toFixed(2));
        }
        var netxian=parseFloat($_netx.val());
        //网点原
           var $_nety=$(this).parent().next().children().eq(0);
        if($_nety.val()!=""){
            if(isNaN(parseFloat($_nety.val()))){
                $_nety.val(0);
            }else{
                 $_nety.val(parseFloat($_nety.val()).toFixed(2));
            }
            
        }   
       var netyuan=parseFloat($_nety.val());
       //网点折价
        
        var $_netz=$(this).parent().next().next().children().eq(0);
          if(isNaN(parseFloat($_netz.val()))){
            $_netz.val(0);
        }else{
             $_netz.val(parseFloat($_netz.val()).toFixed(2));
        }
        var netzhe=parseFloat($_netz.val());
        //网点原未填写不做多余计算
        if(netyuan==""){
           jxsxian=jxsyuan-jxsyuan/100*jxszhe;
           $(this).val(jxsxian); 
        }else{
            jxszhe=(jxsyuan-jxsxian)/jxsyuan*100;
            $_zhe.val(jxszhe.toFixed(2));
            if(jxsxian==0)
            var maoli=0;
            else
            var maoli=(netxian-jxsxian)/jxsxian*100;
            $(this).next().next().val(maoli.toFixed(2));
        }
         jisuanchae();
        
    })
    </script>
    <script>
    //弹出选择我的费用科目树
        $('body').on('click','.feetree',function () {
            var _this = this
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    title:'费用科目树',
                    maxmin:true,
                    content:'{:url("selectFee")}?esuseway=1',
                    btn:'确定',
                    yes:function (i,o) {
                        var id = $(o).find('iframe').contents().find('#renyuan').val()
                        var name = $(o).find('iframe').contents().find('#renyuanname').val()
                        if(id){
                            $(_this).closest('div').prev('div').find('.input-group').hide().find('.feetype').val(id)
                            $(_this).closest('div').prev('div').find('.selectedOnlyOne').show().find('.inin').html(name)
                        }
                        layer.close(i)
                    }
                })
                return  false
        })
        //弹出选择我的费用计入部门树
        $('body').on('click','.select_jrbm',function () {
            var _this = this
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    title:'费用计入部门树',
                    maxmin:true,
                    content:'{:url("selectJrbm")}',
                    btn:'确定',
                    btnAlign:'c',
                    yes:function (i,o) {

                        var id = $(o).find('iframe').contents().find('#renyuan').val()
                        var name = $(o).find('iframe').contents().find('#renyuanname').val()
                        if(id){
                            $(_this).closest('div').prev('div').find('.input-group').hide().find('.jrbm').val(id)
                            $(_this).closest('div').prev('div').find('.selectedOnlyOne').show().find('.inin').html(name)
                        }
                        layer.close(i)
                    }
                })
                return  false
        })

    //关闭多选某一项
    $('body').on('click','.duoxuan .close',function () {
        $(this).closest('.ren').remove()
    })
     //弹出选择sku系列框
        $('#select_product').on('click',function () {
                var index = layer.getFrameIndex(window.name)
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    content:'{:url("selectProduct")}?jid={$jid}'
                })
                return  false
        })
       //弹出选择网点框
        $('#select_net').on('click',function () {
                var index = layer.getFrameIndex(window.name)
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    content:'{:url("selectNet")}?index='+index+'&keyword={$jid}'
                })
                return  false
        })
      //日期范围限制
        var start = {
            elem: '#start',
            format: 'YYYY/MM/DD',
          
            max: '2099-06-16 23:59:59', //最大日期
            istime: true,
            istoday: false,
            choose: function (datas) {
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日

            }
        };
        var end = {
            elem: '#end',
            format: 'YYYY/MM/DD',
            min: laydate.now(),
            max: '2099-06-16 23:59:59',
            istime: true,
            istoday: false,
            choose: function (datas) {
                start.max = datas; //结束日选好后，重置开始日的最大日期
                yjverifyTime.min=datas;
                  $.post("{:url('TiApply/gettwomon')}",{datet:datas},function(re){
                	//alert(re);
                	$("#yjverifyTime").val(re);
                })	
            }
        };
      	var yjverifyTime={
 			elem: '#yjverifyTime',
            format: 'YYYY/MM/DD',
            min: laydate.now(), //设定最小日期为当前日期
            max: '2099-06-16 23:59:59', //最大日期
            istime: true,
            istoday: false,

      	}
      	laydate(yjverifyTime);
        laydate(start);
        laydate(end);
         /*我的常用网点分组*/
           $("#addExaDetail").click(function(){
          var str = '<form method="get" class="form-inline" style="margin:10px"><table class="table-bordered table"><tr><td><label class="radio-inline font-bold"><input type="radio" checked name="inlineRadioOptions" id="inlineRadio1" value="option1">根据原申请编号</label><input type="text" class="form-control"/></td></tr><tr><td><label class="radio-inline font-bold"><input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2">根据待核查任务(温馨说明：待核查任务指领导要求核查但还未下发核查任务书的市场(活动)费用申请)</td></tr><tr><td><label class="radio-inline font-bold"><input type="radio" name="inlineRadioOptions" id="inlineRadio3" value="option3">自主查找核查明细</td></tr><tr><td class="text-center"><button class="btn btn-success">提交</button></td></tr></table></form>'
           layer.open({
              type: 1,
              title:"添加核查明细",
              skin: 'layui-layer-rim', //加上边框
              area: ['800px', '540px'], //宽高
              content: str
            });
        })

           //返回
    $('#fanhui').click(function () {
        if($("#tiapplyid").val()!="")
            parent.window.location="{:url('TiApply/addform')}?aid="+$("#tiapplyid").val();
        else
            parent.layer.close(parent.layer.getFrameIndex(window.name))
    })

     //产品网点搜索自动补全
    $("#net").bsSuggest({
        url: "{:url('netjson2')}?jid="+{$jid},
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        var bool = false
        $('#selected_net .ren').each(function (idx,o) {
            if($(this).data('id') == keyword.id){
                bool = true;
            }
        })
        if(bool == false){
            $('#selected_net').append('<span class="ren netlist" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>')
        }
    });
     //产品单品搜索自动补全
    $("#product").bsSuggest({
        url: "{:url('select/productjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).val('')
        var bool = false
        $('#selected_product .ren').each(function (idx,o) {
            if($(this).data('id') == keyword.id){
                bool = true;
            }
        })
        if(bool == false){
            $('#selected_product').append('<span class="ren prolist" data-id="'+keyword.id+'">'+keyword.key+'<span class="close">×</span></span>');
           	$.post("{:url('TiApply/getpro')}",{id:keyword.id,jid:{$jid}},function(re){
           		if(re!=0){
           			$("#protr").append(re);
           		}
           		
           	})
        }
    });
 //费用类型搜索自动补全
    $(".feetype").bsSuggest({
        url: "{:url('feiyongkemu3json',['esuseway'=>'1'])}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key);
        $(this).val(keyword.id)

    });
    //费用计入部门搜索自动补全
    $(".jrbm").bsSuggest({
        url: "{:url('select/jrbmjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key)
        $(this).val(keyword.id)

    });

       $(document).on("click",".prolist .close",function(){
       		var pid=$(this).parent().attr("data-id");
       		//alert(pid);
       		$("tr[proid="+pid+"]").remove();
       		$(this).parent().remove();
       })
       $(document).on("click",".netlist .close",function(){
       		$(this).parent().remove();
       })
       //取消单选
    $('body').on('click','.selectedOnlyOne .close',function () {
        $(this).closest('.selectedOnlyOne').hide().find('.inin').html('')
        $(this).closest('.selectedOnlyOne').prev('.input-group').show().find('input').val('')
    })
  //添加费用项目
    $('#add').on('click',function () {
        $.post('{:url("addFeiyong")}',function (data) {
            $('#table1').append(data);

            //费用类型搜索自动补全
            $(".feetype").bsSuggest({
                url: "{:url('feiyongkemu3json',['esuseway'=>'1'])}",
                /*effectiveFields: ["userName", "shortAccount"],
                 searchFields: [ "shortAccount"],*/
                effectiveFieldsAlias:{title: "名称"},
                ignorecase: true,
                showHeader: true,
                showBtn: false,     //不显示下拉按钮
                delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                idField: "id",
                keyField: "title",
                clearable: true
            }).on('onSetSelectValue', function (e, keyword, data) {
                $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key)
                $(this).val(keyword.id)
            });
            //费用计入部门搜索自动补全
            $(".jrbm").bsSuggest({
                url: "{:url('select/jrbmjson')}",
                /*effectiveFields: ["userName", "shortAccount"],
                 searchFields: [ "shortAccount"],*/
                effectiveFieldsAlias:{title: "名称"},
                ignorecase: true,
                showHeader: true,
                showBtn: false,     //不显示下拉按钮
                delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                idField: "id",
                keyField: "title",
                clearable: true
            }).on('onSetSelectValue', function (e, keyword, data) {
                $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key)
                $(this).val(keyword.id)
            });
        })
    })
    //删除费用科目项
    $('body').on('click','.del_fi_item',function () {
        $(this).closest('tr').remove()
    })
    //清空产品
    $("#clear_product").click(function(){
    	$(".prolist").remove();
    	$("#protr").html("");
    })
    $("#clear_net").click(function(){
    	$(".netlist").remove();
    })
    function prodetail(pid){
    	 var index = layer.open({
		                    type: 2,
	            			title: '产品详情',
	           				shadeClose: true,
	            			shade: false,
	           				maxmin: true, //开启最大化最小化按钮
	           				area: ['80%', '80%'],
		                    content:'{:url("prodetail")}?pid='+pid
		                })
		               // layer.full(index)
    }
 
         /*
         $("#btns").click(function(){
         	alert(parent.$("#theme").val());
         })*/
         //保存返回
         function baocun(){
            if($("#tiapplyid").val()==""){
                    //没有申请
                    $.ajax({
                        cache: true,
                        type: "POST",
                        url:"{:url('TiApply/addapply')}",
                        data:parent.$('#zhuapply').serialize(),// 你的formid
                        async: false,
                        error: function(request) {
                            alert("Connection error");
                        },
                        success: function(data) {
                            //alert(data);
                            var res=JSON.parse(data);
                            $("#tiapplyid").val(res["aid"]);
                            $.ajax({
                                cache: true,
                                type: "POST",
                                url:"{:url('TiApply/addapplydetail')}",
                                data:$('#f1').serialize(),// 你的formid
                                async: false,
                                error: function(requests) {
                                    alert("Connection error");
                                },
                                success: function(datas) {
                                    //alert(datas);
                                    var res1=JSON.parse(datas);
                                    if(res1["state"]==1){
                                        swal({
                                        title: "完成",
                                        text: "操作已成功",
                                        type: "success"
                                        },function(){
                                            parent.window.location="{:url('TiApply/addform')}?aid="+$("#tiapplyid").val();
                                            parent.layer.close(parent.layer.getFrameIndex(window.name))
                                        });

                                    }else{
                                        swal({
                                        title: "错误",
                                        text:  res1["msg"],
                                        type: "warning"
                                        });
                                    }
                                }
                            });
                        }
                    });
                }else{
                    //有申请
                    $.ajax({
                                cache: true,
                                type: "POST",
                                url:"{:url('TiApply/addapplydetail')}",
                                data:$('#f1').serialize(),// 你的formid
                                async: false,
                                error: function(requests) {
                                    alert("Connection error");
                                },
                                success: function(datas) {
                                    //alert(datas);
                                    var res1=JSON.parse(datas);
                                    if(res1["state"]==1){
                                        swal({
                                        title: "完成",
                                        text: "操作已成功",
                                        type: "success"
                                        },function(){
                                            parent.window.location="{:url('TiApply/addform')}?aid="+$("#tiapplyid").val();
                                            parent.layer.close(parent.layer.getFrameIndex(window.name))
                                        });

                                    }else{
                                        swal({
                                        title: "错误",
                                        text:  res1["msg"],
                                        type: "warning"
                                        });
                                    }
                                }
                            });
                }
         }
         $("#baocunret").click(function(){

         	var res=tijiaoyanzheng();
           // alert(res["msg"]);return;
         	if(res["stauts"]==1){
         		baocun()
         	}else if(res["stauts"]==2){
         		swal({
					title: "错误",
					text:  res["msg"],
					type: "warning"
					});
         	}else if(res["stauts"]==3){
                swal({
                  title: "很抱歉",
                  text: "您申请的活动需要补录基准销量，请补录后再提交，是否马上去补录？",
                  type: "warning",
                  showCancelButton: true,
                  confirmButtonColor: "#DD6B55",
                  confirmButtonText: "确定",
                  cancelButtonText: "取消"
                  
                },
                function(){
                    var jid={$jid};
                    // data: {net:$("#nets").val(),pro:$("#pros").val(),start:$("#start").val(),end:$("#end").val()},
                    var index = layer.open({
                            type:2,
                            title:'网点基准销量补录',
                            area:['80%','80%'],
                            maxmin:true,
                            content:'{:url("Ti_apply/bulu")}?net='+$("#nets").val()+"&jid="+jid+"&pros="+$("#pros").val()+"&start="+$("#start").val()+"&end="+$("#end").val()
                        })
                });
            }else{
               
               if(!confirm("您申请的活动中存在不符合公司规定的单品价格，是否需要修改？点击确定前往修改，点击取消不修改")){
                    baocun();
               }
                
                     
                        
            }
         })
         function baocunadd(){
            if($("#tiapplyid").val()==""){
                    //没有申请
                    $.ajax({
                        cache: true,
                        type: "POST",
                        url:"{:url('TiApply/addapply')}",
                        data:parent.$('#zhuapply').serialize(),// 你的formid
                        async: false,
                        error: function(request) {
                            alert("Connection error");
                        },
                        success: function(data) {
                            var res=JSON.parse(data);
                            $("#tiapplyid").val(res["aid"]);
                            $.ajax({
                                cache: true,
                                type: "POST",
                                url:"{:url('TiApply/addapplydetail')}",
                                data:$('#f1').serialize(),// 你的formid
                                async: false,
                                error: function(requests) {
                                    alert("Connection error");
                                },
                                success: function(datas) {
                                    var res1=JSON.parse(datas);
                                    if(res1["state"]==1){
                                        swal({
                                        title: "完成",
                                        text: "操作已成功",
                                        type: "success"
                                        },function(){
                                            
                                            location.href="{:url('TiApply/addData')}?aid="+$("#tiapplyid").val()+"&jxs={$jid}";
                                        });

                                    }else{
                                        swal({
                                        title: "错误",
                                        text:  res1["msg"],
                                        type: "warning"
                                        });
                                    }
                                }
                            });
                        }
                    });
                }else{
                    //有申请
                    $.ajax({
                                cache: true,
                                type: "POST",
                                url:"{:url('TiApply/addapplydetail')}",
                                data:$('#f1').serialize(),// 你的formid
                                async: false,
                                error: function(requests) {
                                    alert("Connection error");
                                },
                                success: function(datas) {
                                    var res1=JSON.parse(datas);
                                    if(res1["state"]==1){
                                        swal({
                                        title: "完成",
                                        text: "操作已成功",
                                        type: "success"
                                        },function(){
                                            
                                            location.href="{:url('TiApply/addData')}?aid="+$("#tiapplyid").val()+"&jxs={$jid}";
                                        });

                                    }else{
                                        swal({
                                        title: "错误",
                                        text:  res1["msg"],
                                        type: "warning"
                                        });
                                    }
                                }
                            });
                }
         }
         //
         $("#baocunadd").click(function(){
         	var res=tijiaoyanzheng();
         	if(res["stauts"]==1){
         		baocunadd()
         	}else if(res["stauts"]==2){
                swal({
                    title: "错误",
                    text:  res["msg"],
                    type: "warning"
                    });
            }else if(res["stauts"]==3){
                swal({
                  title: "很抱歉",
                  text: "您申请的活动需要补录基准销量，请补录后再提交，是否马上去补录？",
                  type: "warning",
                  showCancelButton: true,
                  confirmButtonColor: "#DD6B55",
                  confirmButtonText: "确定",
                  cancelButtonText: "取消"
                  
                },
                function(){
                    var jid={$jid};
                    // data: {net:$("#nets").val(),pro:$("#pros").val(),start:$("#start").val(),end:$("#end").val()},
                    var index = layer.open({
                            type:2,
                            title:'网点基准销量补录',
                            area:['80%','80%'],
                            maxmin:true,
                            content:'{:url("Ti_apply/bulu")}?net='+$("#nets").val()+"&jid="+jid+"&pros="+$("#pros").val()+"&start="+$("#start").val()+"&end="+$("#end").val()
                        })
                });
            }else{
                 if(!confirm("您申请的活动中存在不符合公司规定的单品价格，是否需要修改？点击确定前往修改，点击取消不修改")){
                    baocunadd();
               }
                        
            }
         })

         function tijiaoyanzheng(){
            $(".num2").each(function(){
                if(isNaN(parseFloat($(this).val()))){
                    $(this).val("0.00");
                }else{
                    $(this).val(parseFloat($(this).val()).toFixed(2));
                }
            })
         	//验证网点
         	var message=[];
         	var netarr=[];
         	var num=0;
         	$(".netlist").each(function(){
         		netarr.push($(this).attr("data-id"));

         	})
         	$("#nets").val(netarr.join(',')); 
         	//产品
         	var proarr=[];
         	$(".prolist").each(function(){
         		proarr.push($(this).attr("data-id"));
         	})
         	$("#pros").val(proarr.join(','));
         
         	if($("#yjverifyTime").val()==""){
         		message["msg"]="预计核销时间必须填写";message["stauts"]=2;
         		return message;
         	}
         	if($("#start").val()==""){
         		message["msg"]="促销开始时间必须填写";message["stauts"]=2;
         		return message;
         	}
         	if($("#end").val()==""){
         		message["msg"]="促销结束时间必须填写";message["stauts"]=2;
         		return message;
         	}
         	if($("#nets").val()==""){
         		message["msg"]="至少选择一个网点";message["stauts"]=2;
         		return message;
         	}
         	if($("#pros").val()==""){
         		message["msg"]="至少选择一个产品";message["stauts"]=2;
         		return message;
         	}
         	//费用记录不能为空
         	var ck=1;
         	$(".feetype").each(function(){
         		num++;
         		if($(this).val()==""){
         			ck=0;
         		}
         	})
         	if(ck==0){
         		message["msg"]="费用名称必须填写";message["stauts"]=2;
         		return message;
         	}
         	ck=1;
         	$(".zonge").each(function(){
         		if($(this).val()==""||$(this).val()=="0"){
         			ck=0;
         		}
         	})
         	if(ck==0){
         		message["msg"]="未税总额必须填写并且不能为0";message["stauts"]=2;
         		return message;
         	}
         	ck=1;
         	$(".paymethod").each(function(){
         		if($(this).val()==0){
         			ck=0;
         		}
         	})
         	if(ck==0){
         		message["msg"]="支付方式必须选择";message["stauts"]=2;
         		return message;
         	}
         	ck=1;
         	$(".jrbm[name='jrbm']").each(function(){
         		if($(this).val()==""){
         			ck=0;
         		}
         	})
         	if(ck==0){
         		message["msg"]="费用计入部门必须选择";message["stauts"]=2;
         		return message;
         	}
         	ck=1;
         	$(".project").each(function(){
         		if($(this).val()=="0"){
         			ck=0;
         		}
         	})
         	if(ck==0){
         		message["msg"]="费用计入方案必须选择";message["stauts"]=2;
         		return message;
         	}
         	//至少一项费用num统计次数
            var zongji=0;
         	$(".zonge").each(function(){
                if(isNaN(parseFloat($(this).val()))){
                    zongji+=0;
                }else{
                    zongji+=parseFloat($(this).val());
                }
            })
            zongji+=parseFloat($("#sumjian").val());
            if(zongji==0){
                message["msg"]="至少有一项费用且费用不能为0";message["stauts"]=2;
                return message;
            }
         	///验证产品项
            //预计销量
            ck=1;
            $(".boxs").each(function(){
                if(parseFloat($(this).val())==0){
                    ck=0;
                }
            })
            if(ck==0){
                message["msg"]="预计销量不能为0";message["stauts"]=2;
                return message;
            }
            //现经销商价不能为空xianjsx
            ck=1;
              $(".xianjsx").each(function(){
                if(isNaN(parseFloat($(this).val()))){
                    ck=0;return false;
                }else{
                    if(parseFloat($(this).val())==0){
                        ck=0;return false;
                    }
                }
            })
            if(ck==0){
                message["msg"]="经销商现供货价不能为空";message["stauts"]=2;
                return message;
            }
             //网点原供货价
            ck=1;
              $(".netyuan").each(function(){
                if(isNaN(parseFloat($(this).val()))){
                    ck=0;return false;
                }else{
                    if(parseFloat($(this).val())==0){
                        ck=0;return false;
                    }
                }
            })
            if(ck==0){
                message["msg"]="网点原供货价不能为空";message["stauts"]=2;
                return message;
            }
           //网点现
             ck=1;
              $(".xiannet").each(function(){
                if(isNaN(parseFloat($(this).val()))){
                    ck=0;return false;
                }else{
                    if(parseFloat($(this).val())==0){
                        ck=0;return false;
                    }
                }
            })
            if(ck==0){
                message["msg"]="网点现供货价不能为空";message["stauts"]=2;
                return message;
            }
            //原零售价
             ck=1;
              $(".yuanp").each(function(){
                if(isNaN(parseFloat($(this).val()))){
                    ck=0;return false;
                }else{
                    if(parseFloat($(this).val())==0){
                        ck=0;return false;
                    }
                }
            })
            if(ck==0){
                message["msg"]="原零售价不能为空";message["stauts"]=2;
                return message;
            }
             //现零售价
             ck=1;
              $(".xianp").each(function(){
                if(isNaN(parseFloat($(this).val()))){
                    ck=0;return false;
                }else{
                    if(parseFloat($(this).val())==0){
                        ck=0;return false;
                    }
                }
            })
            if(ck==0){
                message["msg"]="促销零售价不能为空";message["stauts"]=2;
                return message;
            }
            ck=0;
            $.ajax({
                 type: "POST",
                 url: "{:url('heduijizhun')}",
                 data: {net:$("#nets").val(),pro:$("#pros").val(),start:$("#start").val(),end:$("#end").val()},
                 async:false,//注意添加async：false 同步参数
                 success:function(re){
                   // alert(re);
                    if(re==1){
                        ck=1;
                    }
                 }

            })
            if(ck==0){
                message["msg"]="";message["stauts"]=3;
                return message;
            }
            var flag=0;
            flag=netfanwei();
            if(flag==1){
                message["msg"]="";message["stauts"]=4;
                return message;
            }

         	message["msg"]="";message["stauts"]=1;
         	return message;
         }
         //弹出选择我的常用分组
            
        $('#select_my_net').on('click',function () {
                layer.open({
                    type:2,
                    area:['60%','60%'],
                    title:'我的常用网点分组',
                    maxmin:true,
                    content:'{:url("Ti_apply2/selectMyNetGroup")}?jxs_id='+'{:request()->get("jxs_id")}'
                })
                return  false
        })
    </script>
</body>

</html>
